/*
 * author      : dormi330
 * date        : 2018/6/24
 * description : entity 基类
 */

package com.deep.trade.common;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Date;

public class BaseEntity {
    public static final long BASE_VERSION = 1L;  // 起始版本
    public static final int DR_NOT_DELETE = 0;   // 未删除
    public static final int DR_DELETED = 1;      // 已删除

    protected String id;                         // 32位 uuid
    protected String tenantCode;                 // 租户编码
    protected String createdBy;                  // 创建人 uuid
    protected Date createdAt;                    // 创建时间 yyyy-dd-mm HH:MM:ss
    protected String updatedBy;                  // 更新人 uuid
    protected Date updatedAt;                    // 最后更新时间, 不要在领域对象中操作此值
    protected long version;                      // 版本记录, 用于乐观锁, 不要在领域对象中操作此值
    protected int dr;                            // 逻辑删除标志 1=删除, 0=未删除

    public BaseEntity() {
        Date now = new Date();

        this.createdAt = now;
        this.updatedAt = now;
        this.version = BASE_VERSION;

        this.dr = DR_NOT_DELETE;
    }

    @Override
    public String toString() {
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        return gson.toJson(this);
    }

    public String uglyString() {
        return new Gson().toJson(this);
    }

    // setter getter
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTenantCode() {
        return tenantCode;
    }

    public void setTenantCode(String tenantCode) {
        this.tenantCode = tenantCode;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public int getDr() {
        return dr;
    }

    public void setDr(int dr) {
        this.dr = dr;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }
}
